package design.proxy;

import java.lang.reflect.InvocationHandler;
import java.lang.reflect.Method;

/**
 * 行为代理
 *
 * @author wei.yang on 2018/8/8
 */
public class ProxyHandler implements InvocationHandler {

    private Object object;

    ProxyHandler(Object object) {
        this.object = object;
    }

    @Override
    public Object invoke(Object proxy, Method method, Object[] args) throws Throwable {
        System.out.println("pre design.proxy." + "\t" + Thread.currentThread().getName() + "\t" + System.currentTimeMillis());
        Object result = method.invoke(object, args);
        System.out.println("post design.proxy." + "\t" + Thread.currentThread().getName() + "\t" + System.currentTimeMillis());
        return result;
    }
}
